package com.youlai.boot.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.boot.system.model.dto.PatientDTO;
import com.youlai.boot.system.model.entity.Patient;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.boot.system.model.query.PatientQuery;
import com.youlai.boot.system.model.query.TaskTableQuery;
import com.youlai.boot.system.model.vo.PatientVO;
import com.youlai.boot.system.model.vo.TaskTableVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 患者信息Mapper接口
 *
 * @author
 * @since 2025-03-03 16:25
 */
@Mapper
public interface PatientMapper extends BaseMapper<Patient> {

    /**
     * 获取患者信息分页数据
     *
     * @param page 分页对象
     * @param queryParams 查询参数
     * @return
     */
    Page<PatientVO> getPatientPage(Page<PatientVO> page, PatientQuery queryParams);

    /**
     * 年龄统计
     * @return
     */

    List<PatientDTO> countPatientsByAgeGroups();

    /**
     * 获取患者性别统计数据
     * @return
     */
    @Select("SELECT gender, COUNT(*) as count FROM patient GROUP BY gender")
    List<Map<String, Object>> getGenderCount();
    Page<PatientVO> selectTasksByArchiveStatus(Page<PatientVO> page, PatientQuery queryParamse);

    @Select(" SELECT COUNT(*) FROM patient WHERE addTime BETWEEN #{startDate} AND #{endDate}")
    long countPatientsByDateRange(@Param("startDate") LocalDateTime startDate,@Param("endDate") LocalDateTime endDate);

}
